<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./css/main.css">

    <link rel="stylesheet" href="./css/bootstrap.min.css">
    <link rel="stylesheet" href="./css/fontawesome/css/all.min.css">
    <script src="./css/fontawesome/js/all.min.js"></script>
</head>

<body>

    <div class="thinksite">
        <div class="top">
            <h1>XXX管理系统</h1>

            <button data-action="logout" class="btn btn-link">注销</button>
        </div>
        <div class="main">
            <div class="menus">
                <ul>
                    <li> <a target="contentIframe" href="./pages/users/users.html">用户管理</a> </li>
                </ul>
            </div>
            <div class="content">
                <iframe id="iframe" name="contentIframe" src=""></iframe>
            </div>
        </div>
    </div>
    <script type="module">
        import PocketBase from './js/pocketbase.es.js';
        import _on from './js/_on.js';

        const pb = new PocketBase('http://127.0.0.1:8090');

        // 判断是否登录
        if (pb.authStore.token === '') {
            // 未登录，跳转登录界面
            location.href = './login.html';
        }


        _on('click', {
            logout() {
                // 注销
                pb.authStore.clear();
                // 返回登录页面
                location.href = './login.html';
            }
        })


        // http://127.0.0.1:5500/20230714/index.html?page=http://127.0.0.1:5500/20230714/pages/users/add-user.html
        // http://127.0.0.1:5500/20230714/index.html

        // 保证用户在刷新后依然停留在当前页面
        const usp = new URLSearchParams(location.search);
        const page = Object.fromEntries(usp.entries()).page;
        if (page !== undefined) {
            iframe.src = page;
        } else {
            iframe.src = './pages/users/users.html';
        }

    </script>




</body>

</html>